<template>
	<!--评分配置-评分类型-->
	<a-card :bordered="false">
		<!-- 查询区域 -->
		<div class="table-page-search-wrapper">
			<a-form layout="inline" @keyup.enter.native="searchQuery">
				<a-row :gutter="24">
					<a-col :xl="5" :lg="8" :md="11" :sm="24">
						<a-form-item label="评分类型">
							<div style="display: flex;align-items: center;">
								<j-dict-select-tag placeholder="请选择评分类型" v-model="queryParam.type" dictCode="score_type"></j-dict-select-tag>
							</div>
						</a-form-item>
					</a-col>
					<a-col :xl="5" :lg="8" :md="11" :sm="24">
						<a-form-item label="分类内容">
							<a-input placeholder="请输入分类内容" v-model="queryParam.name"></a-input>
						</a-form-item>
					</a-col>
					<a-col :xl="5" :lg="8" :md="11" :sm="24">
						<a-form-item label="加减类型">
							<a-select :options="modifiedTypeList" placeholder="请选择使用状态"
								v-model="queryParam.plusminusType"></a-select>
						</a-form-item>
					</a-col>
					<a-col :xl="4" :lg="6" :md="8" :sm="24">
						<span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
							<a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
							<a-button type="primary" @click="searchReset" icon="reload"
								style="margin-left: 8px">重置</a-button>
						</span>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<!-- 查询区域-END -->
		<!-- 操作按钮区域 -->
		<div class="table-operator">
			<a-button @click="handleAdds('add','oneType')" icon="plus"
				style="background-color:#32cd99;color: white;">新增配置</a-button>
		</div>
		<!-- table区域-begin -->
		<div>
			<a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns"
				:dataSource="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
				@change="handleTableChange">
				<template slot="states" slot-scope="text,record">
					<a-switch :checked="record.status === '1' ? true:false" @change="updata($event,record)" />
				</template>
				<template slot="action" slot-scope="text, record">
					<a @click="handleAdds('edit',record)" style="margin-right: 10px;">编辑 </a>
				</template>
			</a-table>
		</div>
		<config-modal ref="modalForm" @ok="modalFormOk"></config-modal>
	</a-card>
</template>
<script>
	import {
		httpAction,
		getAction
	} from '@/api/manage'
	import '@/assets/less/TableExpand.less'
	import {
		mixinDevice
	} from '@/utils/mixin'
	import {
		JeecgListMixin
	} from '@/mixins/JeecgListMixin'
	import configModal from './components/configModal'
	import {
		set
	} from 'vuedraggable'
	export default {
		name: 'Devicetype',
		mixins: [JeecgListMixin, mixinDevice],
		components: {
			configModal
		},
		data() {
			return {
				description: '类别管理页面',
				// 表头
				columns: [{
						title: '评分类型',
						align: "center",
						dataIndex: 'type',
						customRender: function(text, r, index) {
							return text === '1'?'招采评价':text === '2'?'平台评价':text === '3'?'移动端评价':''
						}
					},
					{
						title: '分类内容',
						align: "center",
						dataIndex: 'name'
					},
					{
						title: '加减类型',
						align: "center",
						dataIndex: 'plusminusType',
						customRender: function(text, r, index) {
							return text === '1'?'加分':text === '2'?'减分':''
						}
					},
					{
						title: '分数配置',
						align: "center",
						dataIndex: 'score'
					},
					{
						title: '启用',
						align: "center",
						dataIndex: 'states',
						scopedSlots: {
							customRender: 'states'
						}
					},
					{
						title: '操作',
						dataIndex: 'action',
						align: "center",
						width: 210,
						scopedSlots: {
							customRender: 'action'
						}
					}
				],
				modifiedTypeList: [{
					label: '加分',
					value: '1'
				}, {
					label: '减分',
					value: '2'
				}],
				url: {
					list: "/score/wtScoreConfiguration/list",
					edit: "/score/wtScoreConfiguration/edit",
					delete: "",
					deleteBatch: "",
					exportXlsUrl: "",
					importExcelUrl: "",
				},
			}
		},
		created() {
			this.getSuperFieldList();
		},
		computed: {
			importExcelUrl: function() {
				return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
			},
		},
		methods: {
			handleAdds: function(type, record) {
				if (type === 'add') {
					this.$refs.modalForm.title = '新增';
					this.$refs.modalForm.disabled = false;
					this.$refs.modalForm.disableSubmit = false;
					this.$refs.modalForm.add(type, record);
				} else if (type === 'edit') {
					this.$refs.modalForm.title = '编辑';
					this.$refs.modalForm.disabled = false;
					this.$refs.modalForm.disableSubmit = false;
					this.$refs.modalForm.edit(type, record);
				}
			},
			updata(val,record){
			  console.log(1,val,record);
			  let that = this;
			  let params = record;
			  params.status = val === true?'1':'0' 
			  httpAction(this.url.edit, params, 'POST')
			    .then((res) => {
			      if (res.success) {
			        that.$message.success(res.message);
			        this.loadData();
			      } else {
			        that.$message.warning(res.message)
			      }
			    })
			},
			loadData(arg) {
				if (!this.url.list) {
					this.$message.error("请设置url.list属性!")
					return
				}
				//加载数据 若传入参数1则加载第一页的内容
				if (arg === 1) {
					this.ipagination.current = 1;
				}
				var params = this.getQueryParams(); //查询条件
				this.loading = true;
				getAction(this.url.list, params).then((res) => {
					if (res.success) {
						//update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
						this.dataSource = res.result.records || res.result;
						if (res.result.total) {
							this.ipagination.total = res.result.total;
						} else {
							this.ipagination.total = 0;
						}
						//update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
					} else {
						this.$message.warning(res.message)
					}
				}).finally(() => {
					this.loading = false
				})
				getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
					if (res.success) {
						this.projectList = [];
						let treeList = res.result;
						this.projectList = [...treeList].map((v) => ({
							...v,
							value: v.id,
							label: v.departName,
						}))
					}
				})
			},
			initDictConfig() {},
			getSuperFieldList() {
				let fieldList = [];
				fieldList.push({
					type: 'string',
					value: 'parentId',
					text: '父id',
					dictCode: ''
				})
				fieldList.push({
					type: 'string',
					value: 'name',
					text: '名称',
					dictCode: ''
				})
				fieldList.push({
					type: 'int',
					value: 'type',
					text: '类型 0一级 1 二级 2 级',
					dictCode: ''
				})
				fieldList.push({
					type: 'int',
					value: 'num',
					text: '数量',
					dictCode: ''
				})
				this.superFieldList = fieldList
			},

		}
	}
</script>
<style scoped>
	@import '~@assets/less/common.less';
</style>